package cn.bdqn.service.impl;

import cn.bdqn.bean.result.Page;
import cn.bdqn.domain.Accept;
import cn.bdqn.mapper.AcceptMapper;
import cn.bdqn.service.AcceptService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(value = "/acceptService")
public class AcceptServiceImpl implements AcceptService {

    @Autowired
    private AcceptMapper acceptMapper;

    @Override
    public Page<Accept> queryAll(Integer startNum) {
        Page page=new Page();

        Integer pageSize = page.getPageSize();
        //判断当前是第几页,如果startNum为空
        PageHelper.startPage(startNum != 0 ? startNum:1,pageSize);
        List<Accept> acceptList=acceptMapper.selectAll();

        //分页
        PageInfo<Accept> pageInfo=new PageInfo<Accept>(acceptList);
        //获取分页之后的数据
        page.setMenuList(pageInfo.getList());
        //总记录数
        page.setTotalRecord((int)pageInfo.getTotal());
        System.out.println(page);
        //返回分页对象
        return  page;
    }

    @Override
    public Page<Accept> queryBySelective(Accept accept, Integer startNum) {
        Page page=new Page();

        Integer pageSize = page.getPageSize();
        //判断当前是第几页,如果startNum为空
        PageHelper.startPage(startNum != 0 ? startNum:1,pageSize);
        List<Accept> acceptList=acceptMapper.selectBySelective(accept);

        //分页
        PageInfo<Accept> pageInfo=new PageInfo<Accept>(acceptList);
        //获取分页之后的数据
        page.setMenuList(pageInfo.getList());
        //总记录数
        page.setTotalRecord((int)pageInfo.getTotal());
        System.out.println(page);
        //返回分页对象
        return  page;
    }

    @Override
    public Accept queryById(Integer id) {
        return acceptMapper.selectByPrimaryKey(id);
    }

    @Override
    public void addSelective(Accept accept) {
        acceptMapper.insertSelective(accept);
    }

    @Override
    public void changeByPrimaryKeySelective(Accept accept) {
        acceptMapper.updateByPrimaryKeySelective(accept);
    }

    @Override
    public void removeById(Integer id) {
        acceptMapper.deleteByPrimaryKey(id);
    }
}
